local xiabian = fk.CreateSkill {
  name = "lz__xiabian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lz__xiabian"] = "黠变",
  [":lz__xiabian"] = "锁定技，每轮开始时，你须声明【杀】或【桃】中一项：此轮中央区有之的出牌阶段结束时，你视为使用另一项，否则你能将两张牌当此项使用。",
  ["#lz__xiabian-choice"] = "黠变：请声明一项：",
  ["@lz__xiabian-round"] = "黠变",
  ["#lz__xiabian-use"] = "黠变：你可将两张牌当【%arg】使用",
  ["#lz__xiabian-askuse"] = "黠变：请视为使用【%arg】。",

  -- ["$lz__xiabian1"] = "",
  -- ["$lz__xiabian2"] = "",
}

local DIY = require "packages/diy_utility/diy_utility"

xiabian:addEffect(fk.RoundStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xiabian.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = { "slash", "peach", },
      skill_name = xiabian.name,
      prompt = "#lz__xiabian-choice",
      cancelable = false,
    })
    room:setPlayerMark(player, "@lz__xiabian-round", choice)
  end,
})

xiabian:addEffect(fk.EventPhaseEnd, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xiabian.name) and target.phase == Player.Play and player:getMark("@lz__xiabian-round") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local names = { "slash", "peach", }
    table.removeOne(names, player:getMark("@lz__xiabian-round"))
    local virtual_use = names[1]
    if table.find(DIY.getCenterCards(room), function(id)
      return Fk:getCardById(id).trueName == player:getMark("@lz__xiabian-round") end) then
      room:askToUseVirtualCard(player, {
        name = virtual_use,
        skill_name = xiabian.name,
        prompt = "#lz__xiabian-askuse:::" .. virtual_use,
        cancelable = false,
      })
    else
      room:askToUseVirtualCard(player, {
        name = player:getMark("@lz__xiabian-round"),
        skill_name = xiabian.name,
        prompt = "#lz__xiabian-use:::" .. player:getMark("@lz__xiabian-round"),
        cancelable = true,
        card_filter = {
          n = 2,
          cards = player:getCardIds("he"),
        },
      })
    end
  end,
})

xiabian:addAcquireEffect(function(self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

return xiabian
